﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity.Migrations;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using BaseData;
using BaseData.Exts;
using BaseData.HelperEzui;
using BaseData.Models;
using BaseData.ModelsPlex.CMS;
using BaseLib.Helper;
using WebUI.Ashx.Acc.Staff;

namespace WebUI
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private Web_Base_News_Node_Ext nodeExt = new Web_Base_News_Node_Ext();
        protected IM_News_Node_Ext IM_News_Node_Ext;
        public WebForm2()
        {
            this.IM_News_Node_Ext = new IM_News_Node_Ext();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // var nodeExt1 = this.CMS_Node_IM_Ext.Insert(new Web_Base_News_Node_Ext());
            // this.CMS_Node_IM_Ext.Save();
            // var nodeExt2 = this.IM_News_Node_Ext.InsertBySave(new Web_Base_News_Node_Ext());
            // var nodeExt3 = this.CMS_Node_IM_Ext.Insert(new Web_Base_News_Node_Ext());
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var ctx = new ContextExt())
            {
                var nodes = ctx.Web_Base_News_Node_Ext.FirstOrDefault(w => (w.NodeId ?? 0) == 1);
                if (nodes != null)
                    this.NodeExt(nodes);
                else
                    ctx.Web_Base_News_Node_Ext.Add(this.NodeExt(new Web_Base_News_Node_Ext()));
                ctx.SaveChanges();
            }
        }

        private Web_Base_News_Node_Ext NodeExt(Web_Base_News_Node_Ext entityExt)
        {
            this.nodeExt.Memo = System.DateTime.Now.ToString(CultureInfo.InvariantCulture);
            return this.nodeExt;
        }

        public T Insert<T>(T t)
        {
            if (t == null) throw new ArgumentException("T类型不能为空");
            return t;
        }
    }
}